home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
LIFER__
/
PROTO
/
P
/
PD_LIFE_.C
< prev
next >
Wrap
Text File
|
1991-08-02
|
12KB
|
305 lines
/* PD_LIFE_INPUT */
/* File name: LIFE_INPUT */
/* Function: Handle a modal dialog */
/* History: 7/27/91 Original by Prototyper 3.0 */
#include "PCommonLife.h" /* Common */
#include "Common_Life.h" /* Common */
#include "PUtils_Life.h" /* General Utilities */
#include "Utils_Life.h" /* General Utilities */
#include "PA_Life_Alert.h" /* Alert */
#include "PD_LIFE_INPUT.h" /* This file */
#include "LIFE_INPUT.h" /* The user file */
/* ======================================================= */
static Boolean ExitDialog; /* Flag used to exit the Dialog */
static Point MyPt; /* Current list selection point */
static OSErr MyErr; /* OS error returned */
static DialogPtr GetSelection; /* Pointer to this dialog */
static GrafPtr SavedPort; /* Previous grafport */
/* Prototypes */
/* Filter routine for modal dialog routine */
static pascal Boolean MyFilter (DialogPtr theDialog ,EventRecord *theEvent,short *itemHit);
/* This is an update routine for non-controls in the dialog */
/* This is executed after the dialog is uncovered by an alert */
static void Refresh_Dialog(void); /* Refresh the dialogs non-controls */
/* ======================================================= */
/* Initialize the modal dialog, globals and call users routine */
void I_PD_LIFE_INPUT()
{
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
short Index; /* For looping */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem, CTempItem; /* Control handle */
Str255 sTemp; /* Get text entered, temp holding */
short itemHit; /* Get selection */
short temp; /* Get selection, temp holding */
D_Init_LIFE_INPUT();
} /* End of procedure */
/* ======================================================= */
/* Filter routine for dialog events */
static pascal Boolean MyFilter (theDialog ,theEvent,itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
Point MyPt; /* Current list selection point */
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
short chCode; /* Key entered */
long LTemp; /* Used for time delay */
char MyCmdKey; /* The command key */
Boolean CmdDown; /* Flag for command key used */
Boolean valMyFilter; /* Value to return */
valMyFilter = D_Filter_LIFE_INPUT(theDialog, theEvent, itemHit);/* Call the user routine */
if ((theEvent->what == updateEvt) && ((WindowPtr)theEvent->message == theDialog))/* Only do on an update */
{
BeginUpdate(theDialog); /* Start the update */
DrawDialog(theDialog); /* Draw the controls */
valMyFilter = TRUE; /* Pass out this special itemHit number */
*itemHit = 32000; /* Our special ID */
}
if (theEvent->what == mouseDown) /* Only do on a mouse click */
{
MyPt = theEvent->where; /* Get the point where the mouse was clicked */
GlobalToLocal(&MyPt); /* Convert global to local */
}
if (theEvent->what == keyDown)
{
chCode = theEvent->message & charCodeMask; /* Get character */
MyCmdKey = (char)chCode; /* Change to ASCII */
CmdDown = ((theEvent->modifiers / cmdKey) != 0);/* Get command key state */
if (CmdDown == TRUE) /* Do if command key was down */
{
if ((MyCmdKey == 'x') || (MyCmdKey == 'X'))
{
DlgCut(theDialog);
valMyFilter = TRUE;
}
else if ((MyCmdKey =='c') || (MyCmdKey == 'C'))
{
DlgCopy(theDialog);
valMyFilter = TRUE;
}
else if ((MyCmdKey =='v') || (MyCmdKey == 'V'))
{
DlgPaste(theDialog);
valMyFilter = TRUE;
}
}
else if ((chCode == 13) || (chCode == 3)) /* CR or Enter */
{
valMyFilter = TRUE; /* Flag we got a hit */
*itemHit = 1; /* Default for CR */
GetDItem (theDialog ,*itemHit, &DType, &DItem, &tempRect);/* Get the item */
if (DType == (ctrlItem + btnCtrl)) /* If a button then ... */
{
CItem = (ControlHandle)DItem; /* Make it a controlhandle */
HiliteControl(CItem, 10); /* Hilite it */
LTemp = TickCount() + 15; /* Flash the button for 1/4 second */
do
{}
while (LTemp > TickCount());
HiliteControl(CItem, 0); /* UnHilite it */
}
}
}
return(valMyFilter);
}
/* ======================================================= */
/* ======================================================= */
/* This is an update routine for non-controls in the dialog */
/* This is executed after the dialog is uncovered by an alert */
static void Refresh_Dialog() /* Refresh the dialogs non-controls */
{
Rect rTempRect; /* Temp rectangle used for drawing */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
SetPort(GetSelection); /* Point to our dialog window */
rTempRect = tempRect; /* Save the current contents of tempRect */
GetDItem(GetSelection,Res_Dlg_NEXT,&DType,&DItem,&tempRect);/* Get the item handle */
PenSize(3, 3); /* Change pen to draw thick default outline */
InsetRect(&tempRect, -4, -4); /* Draw outside the button by 1 pixel */
FrameRoundRect(&tempRect, 16, 16); /* Draw the outline */
PenSize(1, 1); /* Restore the pen size to the default value */
/* Draw a line, Drawn line2 */
PenSize(3,3); /* Set a wider pen width */
MoveTo(0,20); /* Horz,vert, Move to starting position */
LineTo(299,20); /* Horz,vert, Draw to the ending position */
PenSize(1,1); /* Back to default pen size */
/* Draw a line, Drawn line2-3 */
PenSize(3,3); /* Set a wider pen width */
MoveTo(0,70); /* Horz,vert, Move to starting position */
LineTo(299,70); /* Horz,vert, Draw to the ending position */
PenSize(1,1); /* Back to default pen size */
tempRect = rTempRect; /* Restore the current contents of tempRect */
TextSize(10);
TextFont(courier); /* Select the Font that we want */
/* Draw a string of text, Static Text */
SetRect(&rTempRect, 0,0,300,15);
GetIndString(sTemp,Res_Dlg_Static_Text6,1); /* Get the string */
TextBox(&sTemp[1], sTemp[0], &rTempRect,teJustLeft);
TextSize(12);
TextFont(systemFont); /* Select the Font that we want */
TextFace(0); /* Select the style that we want */
D_Refresh_LIFE_INPUT(GetSelection); /* Call user refresh routine */
}
/* ======================================================= */
void PD_LIFE_INPUT()
{
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
short Index; /* For looping */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
ControlHandle CTempItem; /* temp Control handle */
Str255 sTemp; /* Get text entered, temp holding */
short itemHit; /* Get selection */
short temp; /* Get selection, temp holding */
TEHandle ThisEditText; /* Handle to get the Dialogs TE record */
DialogPeek TheDialogPtr; /* Pointer to Dialogs definition record, contains the TE record */
Boolean good_values = 1; /* FLAG USED TO CHECK IF VALUES FOR X & Y ARE GOOD */
GetPort(&SavedPort); /* Get the previous grafport */
GetSelection = GetNewDialog(Res_D_LIFE_INPUT, NIL, (Ptr)-1);/* Bring in the dialog resource */
tempRect = GetSelection->portRect; /* Get window size, we will now center it */
tempRect.top = ((screenBits.bounds.bottom - screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) / 2;/* Center vert */
tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) / 2;/* Center Horz */
MoveWindow(GetSelection, tempRect.left, tempRect.top, TRUE);/* Now move the window to the proper position */
ShowWindow(GetSelection); /* Open a dialog box */
SelectWindow(GetSelection); /* Lets see it */
SetPort(GetSelection); /* Prepare to add conditional text */
TheDialogPtr = (DialogPeek)GetSelection; /* Get to the inner record */
ThisEditText = TheDialogPtr->textH; /* Get to the TE record */
HLock((Handle)ThisEditText); /* Lock it for safety */
(*ThisEditText)->txSize = 12; /* TE Point size */
TextSize(12); /* Window Point size */
(*ThisEditText)->txFont = systemFont; /* TE Font ID */
TextFont(systemFont); /* Window Font ID */
(*ThisEditText)->txFont = 0; /* TE Font ID */
(*ThisEditText)->fontAscent = 12; /* Font ascent */
(*ThisEditText)->lineHeight = 12 + 3 + 1; /* Font ascent + descent + leading */
HUnlock((Handle)ThisEditText); /* UnLock the handle when done */
/* Setup initial conditions */
Refresh_Dialog(); /* Draw any Lists, lines, or rectangles */
ExitDialog = FALSE; /* Do not exit dialog handle loop yet */
D_Setup_LIFE_INPUT(GetSelection); /* Call user Dialog setup routine */
do /* Start of dialog handle loop */
{
ModalDialog(&MyFilter, &itemHit); /* Wait until an item is hit */
if (itemHit == 32000) /* Check for update */
{
Refresh_Dialog(); /* Draw any Lists, lines, or rectangles*/
EndUpdate(GetSelection); /* End of the update*/
}
else
{
GetDItem(GetSelection, itemHit, &DType, &DItem, &tempRect);
}
D_Hit_LIFE_INPUT(GetSelection,itemHit,&ExitDialog);/* Let user handle the item hit */
/* Handle it real time */
if (itemHit ==Res_Dlg_NEXT) /* Handle the Button being pressed */
{
/* CHECK VALUES OF X & Y */
good_values = CHECKXY(GetSelection, DType, DItem, tempRect);
if (good_values)
{
STORE_VALUES(GetSelection, DType, DItem, tempRect);
}
}
if (itemHit ==Res_Dlg_Cancel) /* Handle the Button being pressed */
{
/* QUIT PROGRAM */
ExitDialog = TRUE;
doneFlag = TRUE; /* Close this dialog, exit */
}
if (itemHit ==Res_Dlg_OK2) /* Handle the Button being pressed */
{
/* CHECK VALUES OF X & Y */
good_values = CHECKXY(GetSelection, DType, DItem, tempRect);
if (good_values)
{
STORE_VALUES(GetSelection, DType, DItem, tempRect);
ExitDialog = TRUE;
/* BRING UP DISPLAY WINDOW */
Open_LIFE_WINDOW();
/* DISPLAY & COMPUTE GENERATION */
LIFE_PROGRAM();
}
}
}
while (ExitDialog == FALSE); /* Handle dialog items until exit selected */
D_Exit_LIFE_INPUT(GetSelection); /* Exiting the modal dialog */
SetPort(SavedPort); /* Restore the previous grafport */
DisposDialog(GetSelection); /* Flush the dialog out of memory */
} /* End of procedure */